﻿using httpLibrary;
using NestClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace NestTestForm
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //MyNestClient.Intance.AddIndex("movie_db");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            for(int i = 0;i < 20;i++)
            {
                var tweet = new Tweet
                {
                    Id = i,
                    User = "kimchy",
                    PostDate = DateTime.Now,
                    Message = "Trying out NEST, so far so good?"
                };

                var rs = MyNestClient.Intance.InsertDataToIndex(tweet, "movie_db");
                Console.WriteLine(rs.ToString());
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            var rs = MyNestClient.Intance.DeleteDataFromIndex(1, "movie_db");
            Console.WriteLine(rs.ToString());
        }

        private void button4_Click(object sender, EventArgs e)
        {
            var rs = MyNestClient.Intance.DeleteIndex("xsy_db");
            Console.WriteLine(rs.ToString());
        }
        NBClass nb = new NBClass();
        private void button5_Click(object sender, EventArgs e)
        {
            //MyNestClient.Intance.AddIndex("xsy_db");
            List<string> parm = new List<string>();
            parm.Add("http://www.xapi.edu.cn/");
            parm.Add("");
            nb.Start(parm);
            //nb.Start("http://vodfile2.news.cn/data/cdn_transfer/66/7E/666ca79bbadf266f9d7d06827f88b0c9e66d1a7e.mp4");
        }

        private void button6_Click(object sender, EventArgs e)
        {
            //Dictionary<string, string> parms = new Dictionary<string, string>();
            //parms.Add("Content", "计算机");
            //object rs = MyNestClient.Intance.SearchData(parms);
            //Console.WriteLine(rs);
            for (int i = 0; i < 10000000;i++ )
            {
                ThreadPool.QueueUserWorkItem(TaskMethod, i);
            }
        }

        private void TaskMethod(object state)
        {
            int index = (int)state;
            Thread.Sleep(500);
            Console.WriteLine(index.ToString());
        }

        private void button7_Click(object sender, EventArgs e)
        {
            nb.SecondStart();
        }
    }
}
